package net.trustie.model;
import net.trustie.utils.DateHandler;
import net.trustie.utils.StringHandler;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.ExtractBy.Source;
import core.AfterExtractor;
import core.Page;
import core.ValidateExtractor;


public class ibm_post_Model implements AfterExtractor, ValidateExtractor {

	private String Url = "";

	@ExtractBy("//*[@id='dw-summary-area']/div[2]/p[2]/text()")
	private String post_time="";

	@ExtractBy("//*[@id='numCmts']/text()")
	private String reply_num = "";

	@ExtractBy(value = "//*[@id='ibm-leadspace-body']/h1/text()", source = Source.RawHtml)
	private String post_title = "";

	/*@ExtractBy("//*[@id='ibm-content-main']/div[1]/allText()")*/
	private String post_content = "";

	@ExtractBy("//*[@id='dw-summary-area']/div[2]/p[1]/a/text()")
	private String author_name= "";
	private String extractTime = "";

	private int history = 0;

	public void afterProcess(Page page) {
		// 处理帖子的url
		this.Url = page.getPageUrl();
		// 处理extractorTime
				this.extractTime = DateHandler.getExtractTime();


		/*// 处理帖子的回复次数
		this.replyNum = StringHandler.subString(this.replyNum, "回复次数：");

		// 处理帖子的内容
		for (String str : this.tags)
			this.topicContent = StringHandler.subString(this.topicContent,
					str.trim());
		this.topicContent = StringHandler.subString(this.topicContent,
				"更多 分享到：");

		// 处理帖子的提交时间
		this.post_time = DateHandler.formatAllTypeDate(this.post_time,page.getTime());

		
*/
	
	}

	public void validate(Page page) {
		if (StringHandler.isAtLeastOneBlank(this.Url, this.post_title)) {
			page.setResultSkip(this, true);
			return;
		}

		if (!StringHandler.canFormatterInteger(this.reply_num)) {
			page.setResultSkip(this, true);
			return;
		}

		if (!DateHandler.canFormatToDate(this.post_time, this.extractTime)) {
			page.setResultSkip(this, true);
		}	
		
	}

	public String getUrl() {
		return Url;
	}

	public void setUrl(String url) {
		Url = url;
	}

	public String getPost_time() {
		return post_time;
	}

	public void setPost_time(String post_time) {
		this.post_time = post_time;
	}

	public String getReply_num() {
		return reply_num;
	}

	public void setReply_num(String reply_num) {
		this.reply_num = reply_num;
	}

	public String getPost_title() {
		return post_title;
	}

	public void setPost_title(String post_title) {
		this.post_title = post_title;
	}

	public String getPost_content() {
		return post_content;
	}

	public void setPost_content(String post_content) {
		this.post_content = post_content;
	}

	public String getAuthor_name() {
		return author_name;
	}

	public void setAuthor_name(String author_name) {
		this.author_name = author_name;
	}

	public String getExtractTime() {
		return extractTime;
	}

	public void setExtractTime(String extractTime) {
		this.extractTime = extractTime;
	}

	public int getHistory() {
		return history;
	}

	public void setHistory(int history) {
		this.history = history;
	}

	
}

